import { Toaster } from "@/components/ui/toaster";
import { Toaster as Sonner } from "@/components/ui/sonner";
import { TooltipProvider } from "@/components/ui/tooltip";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { BrowserRouter, Routes, Route } from "react-router-dom";
import { UserProvider } from "./contexts/UserContext";
import Layout from "./components/Layout";
import VideoEntry from "./pages/VideoEntry";
import VideoLibrary from "./pages/VideoLibrary";
import ScriptDetail from "./pages/ScriptDetail";
import Login from "./pages/Login";
import Profile from "./pages/Profile";
import Credits from "./pages/Credits";
import NotFound from "./pages/NotFound";
import NavigationSetter from "@/components/NavigationSetter";

const queryClient = new QueryClient();

const App = () => (
  <QueryClientProvider client={queryClient}>
    <UserProvider>
      <TooltipProvider>
        <Toaster />
        <Sonner />
        <BrowserRouter>
          <NavigationSetter />
          <Routes>
            <Route path="/" element={<Layout />}>
              <Route index element={<VideoEntry />} />
              <Route path="library" element={<VideoLibrary />} />
              <Route path="script/:videoId" element={<ScriptDetail />} />
            </Route>
            <Route path="login" element={<Login />} />
            <Route path="profile" element={<Profile />} />
            <Route path="credits" element={<Credits />} />
            {/* ADD ALL CUSTOM ROUTES ABOVE THE CATCH-ALL "*" ROUTE */}
            <Route path="*" element={<NotFound />} />
          </Routes>
        </BrowserRouter>
      </TooltipProvider>
    </UserProvider>
  </QueryClientProvider>
);

export default App;
